<?php
class Forum_Bootstrap 
{
    /**
     * Forum_Config instance
     * 
     * @var Forum_Config
     */
    private static $_config = null; 
    
    public static function run($config)
    {
        self::_initSession();
        
        self::_initLoader();
            
        self::_initConfig($config);
        
        self::_initDbAdapter();
        
        self::_initLocale();
        
        self::_initView();
    }
    
    /**
     * Initialize session data
     */
    private static function _initSession()
    {
        session_start();
    }
    
    /**
     * Register autoload
     * 
     * @return void
     */
    private static function _initLoader()
    {
        require_once "Forum/Loader.php";
        
        Forum_Loader::registerAutoload();
    }
    
    /**
     * Run the MVC layout
     * 
     * @return void
     */
    private static function _initView()
    {
        Forum_Layout::startMvc();
    }
    
    /**
     * Write config object to registry
     * 
     * @return void
     */
    private static function _initConfig($config)
    {
        self::$_config = new Forum_Config($config);
        Forum::register('config', self::$_config);
    }
    
    /**
     *  Sets the default timezone
     */
    private static function _initLocale()
    {
        date_default_timezone_set('Europe/Kiev');
    }
    
    /**
     * Init database connection
     */
    private static function _initDbAdapter() 
    {
        Forum::register('db', Forum_Db::getInstance(array(
            'host'      => self::$_config->db->host,
            'username'  => self::$_config->db->username,
            'password'  => self::$_config->db->password,
            'dbname'    => self::$_config->db->dbname
        )));
    }
    
}